package main

import (
	"crypto/sha256"
	"fmt"
	"math/big"
	"sort"
	"strconv"
)

type stu struct {
	name string
	age  int
}
type stus []stu

func slicetSort() {
	stus := []stu{}
	for i := 0; i < 10; i++ {
		stus = append(stus, stu{
			name: "kso" + strconv.Itoa(i),
			age:  10 + i,
		})
	}
	stus = append(stus, stu{
		name: "kso" + strconv.Itoa(13),
		age:  10 + 13,
	})
	stus = append(stus, stu{
		name: "kso" + strconv.Itoa(1),
		age:  1,
	})
	sortCase(stus)
	for _, ok := range stus {
		fmt.Printf("%s\t %d \t \n", ok.name, ok.age)
	}
}

func (a stus) Len() int {
	return len(a)
}
func (a stus) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}
func (a stus) Less(i, j int) bool {
	ii := hashstring(a[i].name)
	jj := hashstring(a[j].name)
	return ii.Cmp(jj) < 0
}
func sortCase(ss stus) {
	sort.Slice(ss, func(i, j int) bool {
		return ss[i].age > ss[j].age
	})
}
func hashstring(s string) *big.Int {
	hash := sha256.Sum256([]byte(s))
	return new(big.Int).SetBytes(hash[:])
}
func sortksos() {
	newstus := stus{
		stu{
			name: "kso7",
			age:  10,
		}, stu{
			name: "kso1",
			age:  11,
		}, stu{
			name: "kso3",
			age:  9,
		}, stu{
			name: "kso5",
			age:  8,
		},
	}
	for _, v := range newstus {
		ii := hashstring(v.name)
		jj := hashstring(v.name)
		fmt.Printf("%s\t %d \t %s %d\n", ii, jj, "======", ii.Cmp(jj))
	}
	sort.Sort(newstus)
	fmt.Println(newstus)
}
